//
//  HeroDetailViewController.m
//  LOL_PalmarHelper
//
//  Created by dllo on 15/6/19.
//  Copyright (c) 2015年 hantao. All rights reserved.
//

#import "HeroDetailViewController.h"

@interface HeroDetailViewController ()

@end

@implementation HeroDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor lightGrayColor];
    self.navigationItem.title = @"英雄资料";
    
    NSString *path1 = [[NSBundle mainBundle] pathForResource:@"iconfont-zanwushipinicon" ofType:@"png"];
    
    UIImage *image1 = [UIImage imageWithContentsOfFile:path1];
    image1 = [image1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(backAction)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image1 style:UIBarButtonItemStyleDone target:self action:@selector(videoAction)];
    
    self.heroDetail = [[HeroDetailModel alloc] init];
    
    
    [self requestData];
    
    
   
    
   

    
}


-(void)backAction
{


    [self.navigationController popViewControllerAnimated:YES];

}




-(void)videoAction
{
    VideoListViewController *video = [[VideoListViewController alloc] init];
    
    video.tag = self.enName;
    video.heroname = self.heroDetail.displayName;
    [self.navigationController pushViewController:video animated:YES];



}

-(void)requestData
{
    
    
    NSString *url = [NSString stringWithFormat:@"http://lolbox.duowan.com/phone/apiHeroDetail.php?heroName=%@",self.enName];
    
    [AFN AFNGetData:url andBlock:^(id respondes) {
       
        
        if (![respondes isKindOfClass:[@"error" class]]) {
            
            
            
            NSMutableDictionary *dic = respondes;
            
            [self.heroDetail setValuesForKeysWithDictionary:dic];
            self.heroDetail.B = [dic objectForKeyedSubscript:[NSString stringWithFormat:@"%@_B",self.heroDetail.name]];
            self.heroDetail.Q = [dic objectForKeyedSubscript:[NSString stringWithFormat:@"%@_Q",self.heroDetail.name]];
            self.heroDetail.W = [dic objectForKeyedSubscript:[NSString stringWithFormat:@"%@_W",self.heroDetail.name]];
            self.heroDetail.E = [dic objectForKeyedSubscript:[NSString stringWithFormat:@"%@_E",self.heroDetail.name]];
            self.heroDetail.R = [dic objectForKeyedSubscript:[NSString stringWithFormat:@"%@_R",self.heroDetail.name]];
            self.heroDV = [[HeroDetailView alloc] initWithFrame:[[UIScreen mainScreen] bounds] andHero:self.heroDetail];
            self.heroDV.myDelegate = self;
            
            [self.view addSubview:self.heroDV];
            [_heroDV release];
            
            
        }else if ([respondes isKindOfClass:[@"error" class]]) {
            
            
            UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络不给力" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [self.view addSubview:al];
            [al show];
            [al release];

            
        }

             

    }];
    
    
    
}


-(void)presentSecond:(NSString *)enName
{

    HeroDetailViewController *heroC = [[HeroDetailViewController alloc] init];
    heroC.enName = enName;
       
    
    

    [self.navigationController pushViewController:heroC animated:YES];

    
    
    }



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
